package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("configurator/query")
public @caption("表单查询") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("srv_query") class SrvQuery implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
	private @caption("编号") @column("sq_id")    @primary  @notnull  @note("  ") Long sqId;// 主键 非空     
	private @caption("查询名称") @column("sq_name")     @notnull  @note("  ") String sqName;// 非空     
	private @caption("图标") @column("sq_icon")     @notnull  @note("  ") String sqIcon;// 非空     
	private @caption("项目路径") @column("sq_path")     @notnull  @note("  ") String sqPath;// 非空     
	private @caption("查询参数") @column("sq_params") @like  @hidden   @notnull  @note("  ") String sqParams;// 非空     
	private @caption("添加人") @column("sq_editor")     @notnull  @relate("$sqEditor") @RelateClass(SrvUser.class)  @note("  ") Long sqEditor;// 非空     
 	private transient SrvUser $sqEditor;//关联对象[人员信息]
	private @caption("修改时间") @column("sq_update_time")     @notnull  @note("  ") Date sqUpdateTime;// 非空     
	private @caption("添加时间") @column("sq_add_time")     @notnull  @note("  ") Date sqAddTime;// 非空     
	private @caption("状态") @column("sq_status")     @notnull  @note(" 1:正常 0:无效  ") Short sqStatus;// 非空 1:正常 0:无效     
	 
	//默认构造函数
	public SrvQuery(){ 
	
	}
	
	//主键构造函数
	public SrvQuery(Long id){
		this.sqId = id;
	}
	
	/**所有字段构造函数 
	 SrvQuery(
	 	Utils.getString("sqName")//查询名称 [非空]
	 	,Utils.getString("sqIcon")//图标 [非空]
	 	,Utils.getString("sqPath")//项目路径 [非空]
	 	,Utils.getString("sqParams")//查询参数 [非空]
	 	,Utils.getLong("sqEditor")//添加人 [非空]
	 	,Utils.getDate("sqUpdateTime")//修改时间 [非空]
	 	,Utils.getDate("sqAddTime")//添加时间 [非空]
	 	,Utils.getShort("sqStatus")//状态 [非空]
	 )
	**/
	public SrvQuery(String sqName,String sqIcon,String sqPath,String sqParams,Long sqEditor,Date sqUpdateTime,Date sqAddTime,Short sqStatus){
		this.sqName=sqName;
		this.sqIcon=sqIcon;
		this.sqPath=sqPath;
		this.sqParams=sqParams;
		this.sqEditor=sqEditor;
		this.sqUpdateTime=sqUpdateTime;
		this.sqAddTime=sqAddTime;
		this.sqStatus=sqStatus;
	}
	
	//设置非空字段
	public SrvQuery setNotNull(String sqName,String sqIcon,String sqPath,String sqParams,Long sqEditor,Date sqUpdateTime,Date sqAddTime,Short sqStatus){
		this.sqName=sqName;
		this.sqIcon=sqIcon;
		this.sqPath=sqPath;
		this.sqParams=sqParams;
		this.sqEditor=sqEditor;
		this.sqUpdateTime=sqUpdateTime;
		this.sqAddTime=sqAddTime;
		this.sqStatus=sqStatus;
		return this;
	}
	/** 编号 [非空]       **/
	public SrvQuery sqId(Long sqId){
		this.sqId = sqId;
		this.setSeted(F.sqId);
		return this;
	}
	/** 查询名称 [非空]       **/
	public SrvQuery sqName(String sqName){
		this.sqName = sqName;
		this.setSeted(F.sqName);
		return this;
	}
	/** 图标 [非空]       **/
	public SrvQuery sqIcon(String sqIcon){
		this.sqIcon = sqIcon;
		this.setSeted(F.sqIcon);
		return this;
	}
	/** 项目路径 [非空]       **/
	public SrvQuery sqPath(String sqPath){
		this.sqPath = sqPath;
		this.setSeted(F.sqPath);
		return this;
	}
	/** 查询参数 [非空]       **/
	public SrvQuery sqParams(String sqParams){
		this.sqParams = sqParams;
		this.setSeted(F.sqParams);
		return this;
	}
	/** 添加人 [非空] [SrvUser]      **/
	public SrvQuery sqEditor(Long sqEditor){
		this.sqEditor = sqEditor;
		this.setSeted(F.sqEditor);
		return this;
	}
	/** 修改时间 [非空]       **/
	public SrvQuery sqUpdateTime(Date sqUpdateTime){
		this.sqUpdateTime = sqUpdateTime;
		this.setSeted(F.sqUpdateTime);
		return this;
	}
	/** 添加时间 [非空]       **/
	public SrvQuery sqAddTime(Date sqAddTime){
		this.sqAddTime = sqAddTime;
		this.setSeted(F.sqAddTime);
		return this;
	}
	/** 状态 [非空]   1:正常 0:无效     **/
	public SrvQuery sqStatus(Short sqStatus){
		this.sqStatus = sqStatus;
		this.setSeted(F.sqStatus);
		return this;
	}
	
	
	/**
	* 克隆对象
	**/
	public SrvQuery clone(){
		SrvQuery clone = new SrvQuery();
		clone.sqName=this.sqName;
		clone.sqIcon=this.sqIcon;
		clone.sqPath=this.sqPath;
		clone.sqParams=this.sqParams;
		clone.sqEditor=this.sqEditor;
		clone.sqUpdateTime=this.sqUpdateTime;
		clone.sqAddTime=this.sqAddTime;
		clone.sqStatus=this.sqStatus;
		return clone;
	}
	/**
	* 清除缓存
	**/
	public void clear(){
		Cache.clearObject(SrvQuery.M.class);
		Cache.clearValue(SrvQuery.M.class);
		Cache.deleteObject(SrvQuery.class, this.getId());
	}
	
	/**
	* 清除缓存
	**/
	public static void clear(Long id){
		Cache.clearObject(SrvQuery.M.class);
		Cache.clearValue(SrvQuery.M.class);
		Cache.deleteObject(SrvQuery.class, id);
	}
	
	
	/**
	 * 根据ID取表单查询
	 * @param id
	 * @return
	 */
	public static @api SrvQuery get(Long id){		
		return getSrvQueryById(id);
	}
	/**
	 * 设置ID
	 * @param id
	 * @return
	 */
	public void setId(Long id){		
		this.sqId = id;
	}
	
	/**
	 * 获取所有表单查询
	 * @return
	 */
	public static @api List<SrvQuery> list(Map params,Integer size){
		return getSrvQueryList(params,size);
	}
	/**
	 * 获取表单查询分页
	 * @return
	 */
	public static @api Page<SrvQuery> page(Integer page,Integer size,Map params){
		return getSrvQueryPage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取表单查询
	 * @param params
	 * @return
	 */
	public static @api SrvQuery Get(Map params){
		return getSrvQuery(params);
	}
	/**
	 * 获取表单查询数
	 * @return
	 */
	public static @api Long count(Map params){
		return getSrvQueryCount(params);
	}
	/**
	 * 获取表单查询数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getSrvQueryEval(eval,params);
	}
	/**
	 * 获取表单查询图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getSrvQueryStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取表单查询图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getSrvQueryStats(params,sumKey,groupKey,dateType);
	}
	
	/**
	 * 根据ID取表单查询
	 * @param id
	 * @return
	 */
	public static @api SrvQuery getSrvQueryById(Long id){		
		return getSrvQueryDao().getSrvQueryById(id);
	}
	/**
	 * 获取id
	 * @return
	 */
	public Long getId(){
		return this.sqId;
	}
	
	
	/**
	 * 根据ID取表单查询的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			return null;
		}
		String value = null;
		value = Cache.getValue(SrvQuery.class, id);
		if(value==null){
			SrvQuery srvQuery = get(id);
			if(srvQuery!=null){
				String strValue = srvQuery.getSqName$();
				if(!"SqName".equals("SqName"))
					strValue+="("+srvQuery.getSqName$()+")";
				Cache.setValue(SrvQuery.class, id ,strValue);
				value = strValue;
			}else{
				Cache.setValue(SrvQuery.class, id ,"{"+id+"}",30);
				value = "{"+id+"}";
			}
		}
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getSqName$();
		if(!"SqName".equals("SqName"))
			keyValue+="("+this.getSqName$()+")";
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询表单查询对象
	 * @return
	 */
	public static @api SrvQuery find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("sqId", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			strDefinex+=" or sq_name = '"+key.replaceAll("'", "''")+"'";
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return SrvQuery.getSrvQuery(params);
	}
	
	
	/**
	 * 根据关键字查询表单查询
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","sq_id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("sqId", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				strDefinex+=" or sq_name like '%"+strTerm.replaceAll("'", "''")+"%'";
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<SrvQuery> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(SrvQuery srvQuery:list){
			Map map = new HashMap();
			map.put("key",srvQuery.getSqId().toString());
			map.put("value", Utils.js(srvQuery.getKeyValue()));
			if(bObject==true)
				map.put("object",srvQuery);
			result.add(map);
		}
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有表单查询
	 * @return
	 */
	public static @api List<SrvQuery> getSrvQueryList(Map params,Integer size){
		return getSrvQueryDao().getSrvQueryList(params,0,size);
	}
	
	/**
	 * 获取表单查询分页
	 * @return
	 */
	public static @api Page<SrvQuery> getSrvQueryPage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getSrvQueryDao().getSrvQueryPage(page, size , params);
	}
	
	/**
	 * 根据查询条件取表单查询
	 * @param params
	 * @return
	 */
	public static @api SrvQuery getSrvQuery(Map params){
		return getSrvQueryDao().getSrvQuery(params);
	}
	
	/**
	 * 保存一个表单查询
	 * @param srvQuery
	 * @return
	 */
	public static @api SrvQuery saveSrvQuery(SrvQuery srvQuery){
		return getSrvQueryDao().saveSrvQuery(srvQuery);
	}
	
	/**
	 * 根据条件更新表单查询
	 * @param values
	 * @param params
	 */
	public static @api int updateSrvQueryByConfirm(Map values, Map params){
		return getSrvQueryDao().updateSrvQueryByConfirm(values,params);
	}
	
	/**
	 * 修改一个表单查询
	 * @param srvQuery
	 * @return
	 */
	public static @api int updateSrvQuery(SrvQuery srvQuery){
		return getSrvQueryDao().updateSrvQuery(srvQuery);
	}
	
	/**
	 * 更新表单查询非空字段
	 * @param srvQuery
	 */
	public static @api int updateSrvQuery$NotNull(SrvQuery srvQuery){
		return getSrvQueryDao().updateSrvQuery$NotNull(srvQuery);
	}
	
	/**
	 * 获取表单查询数
	 * @return
	 */
	public static @api Long getSrvQueryCount(Map params){
		return getSrvQueryDao().getSrvQueryCount(params);
	}
		
		
	/**
	 * 获取表单查询自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getSrvQueryEval(String eval,Map params){
		return getSrvQueryDao().getSrvQueryEval(eval,params);
	}
	/**
	 * 获取表单查询图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getSrvQueryStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getSrvQueryDao().getSrvQueryStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = SrvQuery.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(SrvQuery.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateSrvQuery(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getSrvQueryDao().updateSrvQueryByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteSrvQuery(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getSrvQueryDao().deleteSrvQueryByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		getSrvQueryDao().removeSrvQueryById(id);
	}
	
	
	/**
	 * 保存表单查询对象
	 * @param params
	 * @return
	 */
	public SrvQuery save(){
		if(this.getSqId()!=null)
			getSrvQueryDao().updateSrvQuery(this);
		else
			return getSrvQueryDao().saveSrvQuery(this);
		return this;
	}
	
	
	/**
	 * 更新表单查询对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getSrvQueryDao().updateSrvQuery$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
		if(Utils.equals(Utils.config("logic_delete"),"true"))
			getSrvQueryDao().removeSrvQueryById(this.getSqId());
		else
			getSrvQueryDao().deleteSrvQueryById(this.getSqId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getSrvQueryDao().executeTransaction(function);
	}
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getSqId(){
		if(this.sqId!=null){
			return this.sqId;
		}
		return this.sqId;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getSqId$(){
		String strValue="";
		 strValue=Utils.string(this.getSqId());
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setSqId$(String strValue){
		if(Utils.empty(strValue)){
			this.sqId=null;
			return;
		}
	 	this.sqId=Utils.parseLong(strValue);
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setSqId(Long sqId){
		this.sqId = sqId;
		this.setSeted(F.sqId);
	}
	
	
	
	
	/*******************************查询名称**********************************/	
	/**
	* 查询名称 [非空]      
	**/
	public String getSqName(){
		if(this.sqName!=null){
			return this.sqName;
		}
		return this.sqName;
	}
	/**
	* 获取查询名称格式化(toString)
	**/
	public String getSqName$(){
		String strValue="";
		 strValue=Utils.string(this.getSqName());
	 	 return strValue;
	}
	/**
	* 根据查询名称反格式化
	**/
	public void setSqName$(String strValue){
		if(Utils.empty(strValue)){
			this.sqName=null;
			return;
		}
	 	this.sqName=strValue;
	}
	
	/**
	* 查询名称 [非空]      
	**/
	public void setSqName(String sqName){
		this.sqName = sqName;
		this.setSeted(F.sqName);
	}
	
	
	
	
	/*******************************图标**********************************/	
	/**
	* 图标 [非空]      
	**/
	public String getSqIcon(){
		if(this.sqIcon!=null){
			return this.sqIcon;
		}
		return this.sqIcon;
	}
	/**
	* 获取图标格式化(toString)
	**/
	public String getSqIcon$(){
		String strValue="";
		 strValue=Utils.string(this.getSqIcon());		 
	 
	 	 return strValue;
	}
	/**
	* 根据图标反格式化
	**/
	public void setSqIcon$(String strValue){
		if(Utils.empty(strValue)){
			this.sqIcon=null;
			return;
		}
		this.sqIcon=Utils.parseString(strValue); 
	 
	}
	
	/**
	* 图标 [非空]      
	**/
	public void setSqIcon(String sqIcon){
		this.sqIcon = sqIcon;
		this.setSeted(F.sqIcon);
	}
	
	
	
	
	/*******************************项目路径**********************************/	
	/**
	* 项目路径 [非空]      
	**/
	public String getSqPath(){
		if(this.sqPath!=null){
			return this.sqPath;
		}
		return this.sqPath;
	}
	/**
	* 获取项目路径格式化(toString)
	**/
	public String getSqPath$(){
		String strValue="";
		 strValue=Utils.string(this.getSqPath());
	 	 return strValue;
	}
	/**
	* 根据项目路径反格式化
	**/
	public void setSqPath$(String strValue){
		if(Utils.empty(strValue)){
			this.sqPath=null;
			return;
		}
	 	this.sqPath=strValue;
	}
	
	/**
	* 项目路径 [非空]      
	**/
	public void setSqPath(String sqPath){
		this.sqPath = sqPath;
		this.setSeted(F.sqPath);
	}
	
	
	
	
	/*******************************查询参数**********************************/	
	/**
	* 查询参数 [非空]      
	**/
	public String getSqParams(){
		if(this.sqParams!=null){
			return this.sqParams;
		}
		return this.sqParams;
	}
	/**
	* 获取查询参数格式化(toString)
	**/
	public String getSqParams$(){
		String strValue="";
		 strValue=Utils.string(this.getSqParams());
	 	 return strValue;
	}
	/**
	* 根据查询参数反格式化
	**/
	public void setSqParams$(String strValue){
		if(Utils.empty(strValue)){
			this.sqParams=null;
			return;
		}
		this.sqParams=strValue;
	}
	
	/**
	* 查询参数 [非空]      
	**/
	public void setSqParams(String sqParams){
		this.sqParams = sqParams;
		this.setSeted(F.sqParams);
	}
	
	
	
	
	/*******************************添加人**********************************/	
	/**
	* 添加人 [非空] [SrvUser]     
	**/
	public Long getSqEditor(){
		if(this.sqEditor!=null){
			return this.sqEditor;
		}
		return this.sqEditor;
	}
	/**
	* 获取添加人格式化(toString)
	**/
	public String getSqEditor$(){
		String strValue="";
		if(this.getSqEditor()!=null){
				strValue+=Utils.string(SrvUser.getKeyValue(this.getSqEditor()));
		}			
	 	 return strValue;
	}
	/**
	* 根据添加人反格式化
	**/
	public void setSqEditor$(String strValue){
		if(Utils.empty(strValue)){
			this.sqEditor=null;
			return;
		}
		SrvUser item = SrvUser.find(strValue);
		if(item!=null){
			this.sqEditor = Utils.parseLong(item.getSuId());
		}
	}
	
	/**
	* 添加人 [非空] [SrvUser]     
	**/
	public void setSqEditor(Long sqEditor){
		this.sqEditor = sqEditor;
		this.setSeted(F.sqEditor);
	}
	
	
	
	
	/**
	* 获取关联对象[人员信息]
	**/	 			
 	public SrvUser get$sqEditor(){
 		if(this.$sqEditor!=null)
 			return this.$sqEditor;
 		com.distribute.framework.model.SrvUser srvUser = null;
		if(this.getSqEditor()!=null){
 			srvUser = SrvUser.get(this.getSqEditor());
 		}
 		return srvUser;
	}
	/*******************************修改时间**********************************/	
	/**
	* 修改时间 [非空]      
	**/
	public Date getSqUpdateTime(){
		if(this.sqUpdateTime!=null){
			return this.sqUpdateTime;
		}
		return this.sqUpdateTime;
	}
	/**
	* 获取修改时间格式化(toString)
	**/
	public String getSqUpdateTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getSqUpdateTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据修改时间反格式化
	**/
	public void setSqUpdateTime$(String strValue){
		if(Utils.empty(strValue)){
			this.sqUpdateTime=null;
			return;
		}
	 	this.sqUpdateTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 修改时间 [非空]      
	**/
	public void setSqUpdateTime(Date sqUpdateTime){
		this.sqUpdateTime = sqUpdateTime;
		this.setSeted(F.sqUpdateTime);
	}
	
	
	
	
	/*******************************添加时间**********************************/	
	/**
	* 添加时间 [非空]      
	**/
	public Date getSqAddTime(){
		if(this.sqAddTime!=null){
			return this.sqAddTime;
		}
		return this.sqAddTime;
	}
	/**
	* 获取添加时间格式化(toString)
	**/
	public String getSqAddTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getSqAddTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据添加时间反格式化
	**/
	public void setSqAddTime$(String strValue){
		if(Utils.empty(strValue)){
			this.sqAddTime=null;
			return;
		}
	 	this.sqAddTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 添加时间 [非空]      
	**/
	public void setSqAddTime(Date sqAddTime){
		this.sqAddTime = sqAddTime;
		this.setSeted(F.sqAddTime);
	}
	
	
	
	
	/*******************************状态**********************************/	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public Short getSqStatus(){
		if(this.sqStatus!=null){
			return this.sqStatus;
		}
		return this.sqStatus;
	}
	/**
	* 获取状态格式化(toString)
	**/
	public String getSqStatus$(){
		String strValue="";
		 if(Utils.equals(Utils.string(this.getSqStatus()),"1"))
			strValue=Utils.string("正常");		 
		 if(Utils.equals(Utils.string(this.getSqStatus()),"0"))
			strValue=Utils.string("无效");		 
	 	 return strValue;
	}
	/**
	* 根据状态反格式化
	**/
	public void setSqStatus$(String strValue){
		if(Utils.empty(strValue)){
			this.sqStatus=null;
			return;
		}
		 if(Utils.equals(strValue,"正常"))
		 	this.sqStatus=Utils.parseShort("1");
		 if(Utils.equals(strValue,"无效"))
		 	this.sqStatus=Utils.parseShort("0");
	}
	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public void setSqStatus(Short sqStatus){
		this.sqStatus = sqStatus;
		this.setSeted(F.sqStatus);
	}
	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(SrvQuery.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(SrvQuery.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(SrvQuery.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(SrvQuery.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(SrvQuery.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${SrvQuery.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvQuery.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvQuery.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(SrvQuery.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${SrvQuery.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvQuery.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvQuery.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(SrvQuery.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		/** 编号 [非空]       **/
		public M sqId(Object sqId){if(proxy)return proxy().sqId(sqId);  this.put("sqId", sqId);return this;};
	 	/** and sq_id is null */
 		public M sqIdNull(){if(proxy)return proxy().sqIdNull();if(this.get("sqIdNot")==null)this.put("sqIdNot", "");this.put("sqId", null);return this;};
 		/** not .... */
 		public M sqIdNot(){if(proxy)return proxy().sqIdNot();this.put("sqIdNot", "not");return this;};
 		public M sqIdNotNull(){if(proxy)return proxy().sqIdNotNull();this.put("sqIdNot", "not");this.put("sqId", null);return this;};
 		public M sqIdNot(Object sqId){if(proxy)return proxy().sqIdNot(sqId);this.put("sqIdNot", "not");this.put("sqId", sqId);return this;};
		/** and sq_id <= ? */
		public M sqIdMin(Object min){if(proxy)return proxy().sqIdMin(min);this.put("sqIdMin", min);return this;};
		/** and sq_id >= ? */
		public M sqIdMax(Object max){if(proxy)return proxy().sqIdMax(max);this.put("sqIdMax", max);return this;};
		public M sqIdIn(String ids){
			if(proxy)return proxy().sqIdIn(ids);  this.put("sqIdIn", ids);return this;
		};	
		/** 查询名称 [非空]       **/
		public M sqName(Object sqName){if(proxy)return proxy().sqName(sqName);  this.put("sqName", sqName);return this;};
	 	/** and sq_name is null */
 		public M sqNameNull(){if(proxy)return proxy().sqNameNull();if(this.get("sqNameNot")==null)this.put("sqNameNot", "");this.put("sqName", null);return this;};
 		/** not .... */
 		public M sqNameNot(){if(proxy)return proxy().sqNameNot();this.put("sqNameNot", "not");return this;};
 		public M sqNameNotNull(){if(proxy)return proxy().sqNameNotNull();this.put("sqNameNot", "not");this.put("sqName", null);return this;};
 		public M sqNameNot(Object sqName){if(proxy)return proxy().sqNameNot(sqName);this.put("sqNameNot", "not");this.put("sqName", sqName);return this;};
		/** 图标 [非空]       **/
		public M sqIcon(Object sqIcon){if(proxy)return proxy().sqIcon(sqIcon);  this.put("sqIcon", sqIcon);return this;};
	 	/** and sq_icon is null */
 		public M sqIconNull(){if(proxy)return proxy().sqIconNull();if(this.get("sqIconNot")==null)this.put("sqIconNot", "");this.put("sqIcon", null);return this;};
 		/** not .... */
 		public M sqIconNot(){if(proxy)return proxy().sqIconNot();this.put("sqIconNot", "not");return this;};
 		public M sqIconNotNull(){if(proxy)return proxy().sqIconNotNull();this.put("sqIconNot", "not");this.put("sqIcon", null);return this;};
 		public M sqIconNot(Object sqIcon){if(proxy)return proxy().sqIconNot(sqIcon);this.put("sqIconNot", "not");this.put("sqIcon", sqIcon);return this;};
		/** 项目路径 [非空]       **/
		public M sqPath(Object sqPath){if(proxy)return proxy().sqPath(sqPath);  this.put("sqPath", sqPath);return this;};
	 	/** and sq_path is null */
 		public M sqPathNull(){if(proxy)return proxy().sqPathNull();if(this.get("sqPathNot")==null)this.put("sqPathNot", "");this.put("sqPath", null);return this;};
 		/** not .... */
 		public M sqPathNot(){if(proxy)return proxy().sqPathNot();this.put("sqPathNot", "not");return this;};
 		public M sqPathNotNull(){if(proxy)return proxy().sqPathNotNull();this.put("sqPathNot", "not");this.put("sqPath", null);return this;};
 		public M sqPathNot(Object sqPath){if(proxy)return proxy().sqPathNot(sqPath);this.put("sqPathNot", "not");this.put("sqPath", sqPath);return this;};
		/** 查询参数 [非空]       **/
		public M sqParams(Object sqParams){if(proxy)return proxy().sqParams(sqParams);  this.put("sqParams", sqParams);return this;};
	 	/** and sq_params is null */
 		public M sqParamsNull(){if(proxy)return proxy().sqParamsNull();if(this.get("sqParamsNot")==null)this.put("sqParamsNot", "");this.put("sqParams", null);return this;};
 		/** not .... */
 		public M sqParamsNot(){if(proxy)return proxy().sqParamsNot();this.put("sqParamsNot", "not");return this;};
 		public M sqParamsNotNull(){if(proxy)return proxy().sqParamsNotNull();this.put("sqParamsNot", "not");this.put("sqParams", null);return this;};
 		public M sqParamsNot(Object sqParams){if(proxy)return proxy().sqParamsNot(sqParams);this.put("sqParamsNot", "not");this.put("sqParams", sqParams);return this;};
		public M sqEditor$on(SrvUser.M value){if(proxy)return proxy().sqEditor$on(value);this.put("SqEditor", value);value.put("on", "sq_editor");return this;};
		/** 添加人 [非空] [SrvUser]      **/
		public M sqEditor(Object sqEditor){if(proxy)return proxy().sqEditor(sqEditor);  this.put("sqEditor", sqEditor);return this;};
	 	/** and sq_editor is null */
 		public M sqEditorNull(){if(proxy)return proxy().sqEditorNull();if(this.get("sqEditorNot")==null)this.put("sqEditorNot", "");this.put("sqEditor", null);return this;};
 		/** not .... */
 		public M sqEditorNot(){if(proxy)return proxy().sqEditorNot();this.put("sqEditorNot", "not");return this;};
 		public M sqEditorNotNull(){if(proxy)return proxy().sqEditorNotNull();this.put("sqEditorNot", "not");this.put("sqEditor", null);return this;};
 		public M sqEditorNot(Object sqEditor){if(proxy)return proxy().sqEditorNot(sqEditor);this.put("sqEditorNot", "not");this.put("sqEditor", sqEditor);return this;};
		public M sqEditorIn(String ids){
			if(proxy)return proxy().sqEditorIn(ids);  this.put("sqEditorIn", ids);return this;
		};	
		/** 修改时间 [非空]       **/
		public M sqUpdateTime(Object sqUpdateTime){if(proxy)return proxy().sqUpdateTime(sqUpdateTime);  this.put("sqUpdateTime", sqUpdateTime);return this;};
	 	/** and sq_update_time is null */
 		public M sqUpdateTimeNull(){if(proxy)return proxy().sqUpdateTimeNull();if(this.get("sqUpdateTimeNot")==null)this.put("sqUpdateTimeNot", "");this.put("sqUpdateTime", null);return this;};
 		/** not .... */
 		public M sqUpdateTimeNot(){if(proxy)return proxy().sqUpdateTimeNot();this.put("sqUpdateTimeNot", "not");return this;};
 		public M sqUpdateTimeNotNull(){if(proxy)return proxy().sqUpdateTimeNotNull();this.put("sqUpdateTimeNot", "not");this.put("sqUpdateTime", null);return this;};
 		public M sqUpdateTimeNot(Object sqUpdateTime){if(proxy)return proxy().sqUpdateTimeNot(sqUpdateTime);this.put("sqUpdateTimeNot", "not");this.put("sqUpdateTime", sqUpdateTime);return this;};
 		/** and sq_update_time >= ? */
 		public M sqUpdateTimeStart(Object start){if(proxy)return proxy().sqUpdateTimeStart(start);this.put("sqUpdateTimeStart", start);return this;};			
 		/** and sq_update_time <= ? */
 		public M sqUpdateTimeEnd(Object end){if(proxy)return proxy().sqUpdateTimeEnd(end);this.put("sqUpdateTimeEnd", end);return this;};
		/** 添加时间 [非空]       **/
		public M sqAddTime(Object sqAddTime){if(proxy)return proxy().sqAddTime(sqAddTime);  this.put("sqAddTime", sqAddTime);return this;};
	 	/** and sq_add_time is null */
 		public M sqAddTimeNull(){if(proxy)return proxy().sqAddTimeNull();if(this.get("sqAddTimeNot")==null)this.put("sqAddTimeNot", "");this.put("sqAddTime", null);return this;};
 		/** not .... */
 		public M sqAddTimeNot(){if(proxy)return proxy().sqAddTimeNot();this.put("sqAddTimeNot", "not");return this;};
 		public M sqAddTimeNotNull(){if(proxy)return proxy().sqAddTimeNotNull();this.put("sqAddTimeNot", "not");this.put("sqAddTime", null);return this;};
 		public M sqAddTimeNot(Object sqAddTime){if(proxy)return proxy().sqAddTimeNot(sqAddTime);this.put("sqAddTimeNot", "not");this.put("sqAddTime", sqAddTime);return this;};
 		/** and sq_add_time >= ? */
 		public M sqAddTimeStart(Object start){if(proxy)return proxy().sqAddTimeStart(start);this.put("sqAddTimeStart", start);return this;};			
 		/** and sq_add_time <= ? */
 		public M sqAddTimeEnd(Object end){if(proxy)return proxy().sqAddTimeEnd(end);this.put("sqAddTimeEnd", end);return this;};
		/** 状态 [非空]   1:正常 0:无效     **/
		public M sqStatus(Object sqStatus){if(proxy)return proxy().sqStatus(sqStatus);  this.put("sqStatus", sqStatus);return this;};
	 	/** and sq_status is null */
 		public M sqStatusNull(){if(proxy)return proxy().sqStatusNull();if(this.get("sqStatusNot")==null)this.put("sqStatusNot", "");this.put("sqStatus", null);return this;};
 		/** not .... */
 		public M sqStatusNot(){if(proxy)return proxy().sqStatusNot();this.put("sqStatusNot", "not");return this;};
 		public M sqStatusNotNull(){if(proxy)return proxy().sqStatusNotNull();this.put("sqStatusNot", "not");this.put("sqStatus", null);return this;};
 		public M sqStatusNot(Object sqStatus){if(proxy)return proxy().sqStatusNot(sqStatus);this.put("sqStatusNot", "not");this.put("sqStatus", sqStatus);return this;};
		public M sqStatusIn(String ids){
			if(proxy)return proxy().sqStatusIn(ids);  this.put("sqStatusIn", ids);return this;
		};	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	/** 获取所有表单查询 **/
		public @api List<SrvQuery> list(Integer size){			
			return getSrvQueryList(this,size);
		}
		/** 获取表单查询分页 **/
		public @api Page<SrvQuery> page(Integer page,Integer size){			
			return getSrvQueryPage(page, size , this);
		}
		/** 根据查询条件取表单查询 **/
		public @api SrvQuery get(){			
			return getSrvQuery(this);
		}
		/** 获取表单查询数 **/
		public @api Long count(){			
			return getSrvQueryCount(this);
		}
		/** 获取表单查询表达式 **/
		public @api <T> T eval(String strEval){			
			return getSrvQueryEval(strEval,this);
		}
		/** 获取表单查询统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getSrvQueryStats(this,sumKey,groupKey,dateType);
		}
		/** 获取表单查询统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getSrvQueryStats(this,sumKey,groupKey,-1);
		}
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateSrvQuery(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteSrvQuery(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String sqId="sqId";
		/** 查询名称 [非空]       **/
		public final static @type(String.class)  String sqName="sqName";
		/** 图标 [非空]       **/
		public final static @type(String.class)  String sqIcon="sqIcon";
		/** 项目路径 [非空]       **/
		public final static @type(String.class)  String sqPath="sqPath";
		/** 查询参数 [非空]       **/
		public final static @type(String.class) @like String sqParams="sqParams";
		/** 添加人 [非空] [SrvUser]      **/
		public final static @type(Long.class)  String sqEditor="sqEditor";
		/** 修改时间 [非空]       **/
		public final static @type(Date.class)  String sqUpdateTime="sqUpdateTime";
	 	/** and sq_update_time >= ? */
 		public final static @type(Date.class) String sqUpdateTimeStart="sqUpdateTimeStart";
 		/** and sq_update_time <= ? */
 		public final static @type(Date.class) String sqUpdateTimeEnd="sqUpdateTimeEnd";
		/** 添加时间 [非空]       **/
		public final static @type(Date.class)  String sqAddTime="sqAddTime";
	 	/** and sq_add_time >= ? */
 		public final static @type(Date.class) String sqAddTimeStart="sqAddTimeStart";
 		/** and sq_add_time <= ? */
 		public final static @type(Date.class) String sqAddTimeEnd="sqAddTimeEnd";
		/** 状态 [非空]   1:正常 0:无效     **/
		public final static @type(Short.class)  String sqStatus="sqStatus";
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	/** 对象的数据库字段描述 **/
	public static enum C{
		sqId("sq_id"),
		sqName("sq_name"),
		sqIcon("sq_icon"),
		sqPath("sq_path"),
		sqParams("sq_params"),
		sqEditor("sq_editor"),
		sqUpdateTime("sq_update_time"),
		sqAddTime("sq_add_time"),
		sqStatus("sq_status"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/**
	* 获取表单查询数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = SrvQuery.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = SrvQuery.getSrvQuery(params);
			else
				value = SrvQuery.getSrvQueryList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  SrvQuery.where().sqId(param).get();
		else if(!Utils.empty(param.toString()))
			value = SrvQuery.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getSqId());
		Utils.fms(map,simple?"id":"sqId",this.getSqId(),this.getSqId$());
		Utils.fms(map,simple?"name":"sqName",this.getSqName(),this.getSqName$());
		Utils.fms(map,simple?"icon":"sqIcon",this.getSqIcon(),this.getSqIcon$());
		Utils.fms(map,simple?"path":"sqPath",this.getSqPath(),this.getSqPath$());
		Utils.fms(map,simple?"params":"sqParams",this.getSqParams(),this.getSqParams$());
		Utils.fms(map,simple?"editor":"sqEditor",this.getSqEditor(),this.getSqEditor$());
		Utils.fms(map,simple?"updateTime":"sqUpdateTime",this.getSqUpdateTime(),this.getSqUpdateTime$());
		Utils.fms(map,simple?"addTime":"sqAddTime",this.getSqAddTime(),this.getSqAddTime$());
		Utils.fms(map,simple?"status":"sqStatus",this.getSqStatus(),this.getSqStatus$());
		if(this.suffix!=null)map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
		map.put("sqId",this.getSqId());
		map.put("sqName",this.getSqName());
		map.put("sqIcon",this.getSqIcon());
		map.put("sqPath",this.getSqPath());
		map.put("sqParams",this.getSqParams());
		map.put("sqEditor",this.getSqEditor());
		map.put("sqUpdateTime",this.getSqUpdateTime());
		map.put("sqAddTime",this.getSqAddTime());
		map.put("sqStatus",this.getSqStatus());
		map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static SrvQuery fromMap(Map map){
		SrvQuery srvQuery = new SrvQuery();
		srvQuery.sqId = Utils.parseLong(map.get("sqId"));
		srvQuery.sqName = Utils.parseString(map.get("sqName"));
		srvQuery.sqIcon = Utils.parseString(map.get("sqIcon"));
		srvQuery.sqPath = Utils.parseString(map.get("sqPath"));
		srvQuery.sqParams = Utils.parseString(map.get("sqParams"));
		srvQuery.sqEditor = Utils.parseLong(map.get("sqEditor"));
		srvQuery.sqUpdateTime = Utils.parseDate(map.get("sqUpdateTime"));
		srvQuery.sqAddTime = Utils.parseDate(map.get("sqAddTime"));
		srvQuery.sqStatus = Utils.parseShort(map.get("sqStatus"));
		return srvQuery;
	}
	
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(SrvQuery old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	public static String getIcon(){
		return "/images/icons/Zoom.png";
	}
	public static String getIconfont(){
		return "icon-chazhao";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,SrvQuery.M params){
		if(params==null)params=new SrvQuery.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/configurator/query.edit.html?";
		if(params.get("sqId")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("sqId"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/configurator/query.html?1=1";
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.sqId(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(SrvQuery.ACT act,SrvQuery.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",SrvQuery.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(SrvQuery.ACT act,SrvQuery.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",SrvQuery.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.ISrvQueryDao getSrvQueryDao(){
		return Utils.getBean("srvQueryDao");
	};
	
}